<template>
	<view class="goods_list">
		<goods-item  v-for="(item,index) in data" :key="index" :img="item.img" :price="item.price" :content="item.content"></goods-item>
	</view>
</template>

<script>
	import goodsItem from "../../components/goods-item/goods-item.vue"
	export default {
		data() {
			return {
				list: [
					{
						img: 'https://gw.alicdn.com/bao/upload/TB16Ya8qLb2gK0jSZK9XXaEgFXa.jpg_Q75.jpg',
						price: ['¥3199','¥3299'],
						content:'Huawei/华为MatePad Pro平板电脑笔记本二合一新品轻薄全面屏影音无线充电'
					}
				],
				data: [],
				loadMoreText: "加载中...",
				showLoadMore: false
			}
		},
		onLoad() {
			this.initData();
		},
		onUnload() {
			this.loadMoreText = "加载更多",
			this.showLoadMore = false;
		},
		onReachBottom() {
			console.log("onReachBottom");
			if (this.data.length > 20) {
				this.loadMoreText = "没有更多数据了!"
				return;
			}
			this.showLoadMore = true;
			setTimeout(() => {
				this.setListData();
			}, 300);
		},
		onPullDownRefresh() {
			console.log('onPullDownRefresh');
			this.initData();
		},
		methods: {
			initData(){
				this.data=[];
				setTimeout(() => {
					for (var i = 0; i < 5; i++) {
						this.data.push(this.list[0])
					}
					uni.stopPullDownRefresh();
				}, 300);
			},
			setListData() {
				for (var i = 0; i < 6; i++) {
					this.data.push(this.list[0])
				}
			}
		},
		components:{
			"goods-item": goodsItem
		}
	}
</script>

<style lang="scss">
	.goods_list {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 0 10rpx;
		background-color: #eee;
	}
</style>
